//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    userInfo: {}
  },
  //事件处理函数
  openRent: function() {
    wx.scanCode({
      onlyFromCamera: true,
      success: function(res) {
        console.log(res);
        var params=new Array();
        var params=res.result.split(",");
        wx.request({
          url: 'https://55300249.qcloud.la/JapariFriends/rent',
          data: {
            userId:params[0],
            book1:params[1],
            book2:params[2]
          },
          method: 'get',
          success: function (res) {
            console.log(res);
          },
          fail: function (res) { },
          complete: function (res) { },
        })
      },
      fail: function(res) {},
      complete: function(res) {},
    })
    
  },
  openReturn:function(){
    wx.scanCode({
      onlyFromCamera: true,
      success: function (res) {
        console.log(res);
        wx.request({
          url: 'https://55300249.qcloud.la/JapariFriends/return',
          data: {
            bookId:res.result
          },
          method: 'get',
          success: function (res) {
            console.log(res);
          },
          fail: function (res) { },
          complete: function (res) { },
        })
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  onLoad: function () {
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })
  }
})
